package com.best.guanfengji

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import com.best.guanfengji.R
import com.best.guanfengji.base.BaseDialogFragment
import com.blankj.utilcode.util.ConvertUtils

class MyInputDialog(private val onInputClickListener:OnInputClickListener): BaseDialogFragment() {

    override fun onStart() {
        super.onStart()
        //设置dialog的大小
        val lp: WindowManager.LayoutParams? = dialog?.window?.attributes
        lp?.width = ConvertUtils.dp2px(360f)
        lp?.height = ConvertUtils.dp2px(300f)
        dialog?.window?.attributes = lp
        dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        dialog?.setCanceledOnTouchOutside(false)
        dialog?.setCancelable(false)
    }

    override fun onCreateView(inflater: LayoutInflater,container: ViewGroup?,savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.dialog_input, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val ib_close = view.findViewById<ImageView>(R.id.ib_close)
        val et_content = view.findViewById<EditText>(R.id.et_content)
        val tv_commit = view.findViewById<TextView>(R.id.tv_commit)

        ib_close.setOnClickListener{
            dismiss()
        }
        tv_commit.setOnClickListener {
            onInputClickListener.onSubmitClick(et_content.text.toString())
            dismiss()
        }

    }

    interface OnInputClickListener{
        fun onSubmitClick(text:String)
    }

}